package com.pet.server.ext.action.pet;
import com.pet.server.ext.ActionBase;
import com.pet.server.ext.ApiError;
import com.pet.server.ext.Result;
import com.pet.server.ext.data.PetEvent;
import com.pet.server.ext.data.PetInfo;
import com.pet.server.ext.service.UserService;
import com.pet.server.ext.util.NumberUtil;
import com.pet.server.ext.util.Parameters;
import com.pet.server.ext.util.StringUtil;

public class Eventremove extends ActionBase{
	public Integer id;
	public Eventremove(){
		 needCheckAuth =true;
	}

	@Override
	public void initParameters(Parameters params) throws ApiError {	
		id = NumberUtil.getInteger(params.getFieldValue("id"));
		if(StringUtil.isEmpty(id)){
			throw ApiError.Type.INVALID_PARAM.toException();
		}
	}
	@Override
	public Result invokeService() throws ApiError {
		UserService userService = new UserService();
	    PetEvent event = userService.findPetEvent(id);
		if(null==event){
			throw ApiError.Type.EXIST_PARAM.toException();
		}
		PetInfo pet = userService.findPetInfoById(event.pet_id);
		if(!StringUtil.equals(pet.user_id, user.user_id)){
			throw ApiError.Type.EXIST_PARAM.toException();
		}
		//删除记录
		userService.deletePetEvent(id);
		Result result = new Result();
	    return result;
	}
}
